package cn.linjianhui.thread;

public class PriorityDemo {

    public static class HightPriority extends Thread {
        int count = 0;
        @Override
        public void run() {
            while(true) {
                synchronized (PriorityDemo.class) {
                    count++;
                    if(count > 10000) {
                        System.out.println("HightPriority finish work!");
                        break;
                    }
                }
            }
        }
    }

    public static class LowPriority extends Thread {
        int count = 0;
        @Override
        public void run() {
            while(true) {
                synchronized (PriorityDemo.class) {
                    count++;
                    if(count > 10000) {
                        System.out.println("LowPriority finish work!");
                        break;
                    }
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        HightPriority hight = new HightPriority();
        LowPriority low = new LowPriority();
        hight.setPriority(Thread.MAX_PRIORITY);
        low.setPriority(Thread.MIN_PRIORITY);
        hight.start();
        low.start();
    }
}
